﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using libCommonTools.Forms;
using libCommonTools.BUS;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI;
using libDAL;
using System.Timers;
using libCommonTools;


namespace libCommonTools.Forms
{
    
    public partial class frmFindCompany : Telerik.WinControls.UI.RadForm
    {
       // private System.Timers.Timer textTimer;
       
        private clsBUS _BUS;
        private clsTimerDelay TimerDelay;
        private string strGRNNo = string.Empty ;
       // private string strSearchType = string.Empty;

        private struct Company
        {
            public string strCompanyID;
            public string strCompanyType;
            public string strSearchType;
            public string strCompanyName;
            public string strCompanyPortID;
        }

        private struct AddressDetails
        { 
            //areacode, areaname, citycode, statecode, coucode, regcode
            public string strAreacode;
            public string strAreaname;
            public string strCitycode;
            public string strCitycodeName;
            public string strStatecode;
            public string strStateName;
            public string strCoucode;
            public string strCouName;
            public string strRegcode;
            public string strZoneCode;
            public string strZoneName;
            public string strGRNNo;
        }

        private struct HolderOfVariables
        {
            public string strFindType;

        }

        private struct PortDetails
        {
            public string strPortID;
            public string strPortName;
        }

        private struct PostDetails
        {
            public string strPostID;
            public string strPostName;
        }

        private struct GeneralMeasurement
        {
            public string strCode;
            public string strDescription;
        }
        private struct CodeDescription
        {
            public string strCode;
            public string strDescription;
        }


        private struct ShipperMeasurement
        {
            public string strCode;
            public string strDescription;
        }

        private bool bolSelected = false;

        private HolderOfVariables HolderVariables;
        private Company strcCompanyG;
        private AddressDetails strcAddressG;
        private PortDetails strcPortDetails;
        private PostDetails strcPostDetails;
        private CodeDescription strcCodeDescription;
        private GeneralMeasurement strGenMeasurement;
        private ShipperMeasurement strShippMeasurement;
    

        private bool get_CheckSelected()
        {
            bool bolStatus = false;
            if (dgvFind.SelectedRows.Count > 0)
            {
                bolStatus = true;
            }
            return bolStatus;
        }

        public string get_CompanyID
          {
              get
              {

                  return this.strcCompanyG.strCompanyID;
              }
          }

        public string get_CompanyType
          {
              get
              {
                  return this.strcCompanyG.strCompanyType;
              }
          }

        public string getset_SearchType
          {
              get
              {
                  return strcCompanyG.strSearchType;
              }
              set
              {
                  strcCompanyG.strSearchType = value;
              }
          }

        public string getset_GRNNumber
        {
            get
            {
                return this.strGRNNo ;
            }
            set
            {
                this.strGRNNo = value;
            }
        }

        public void set_GRNSearchHide()
        {
            chkDateRange.Visible = false;
            dteFrom.Visible = false;
            dteTo.Visible = false;
            lblFrom.Visible = false;
            lblTo.Visible = false;
        }

        public void set_GRNSearchShow()
        {
            chkDateRange.Visible = true;
            dteFrom.Visible = true;
            dteTo.Visible = true;
            lblFrom.Visible = true;
            lblTo.Visible = true;
            chkDateRange.Checked = false;
            dteFrom.Enabled = false;
            dteTo.Enabled = false;
        }

        private void set_FormDesign(string strFindType)
        {
            try
            {
                HolderVariables.strFindType = strFindType;

                if (HolderVariables.strFindType == "Company")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(739, 419);
                    this.MaximumSize = new Size(739, 419);
                    this.dgvFind.Location = new System.Drawing.Point(0, 59);
                }
                else if (HolderVariables.strFindType == "AddressDetails")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(655, 435);
                    this.MaximumSize = new Size(655, 435);
                    this.dgvFind.Location = new System.Drawing.Point(0, 59);
                }
                else if (HolderVariables.strFindType == "Zone")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(442, 419);
                    this.MaximumSize = new Size(442, 419);
                    this.dgvFind.Location = new System.Drawing.Point(0, 59);
                }
                else if (HolderVariables.strFindType == "GRN")
                {
                    set_GRNSearchShow();
                    this.Size = new Size(739, 419);
                    this.MaximumSize = new Size(739, 419);
                    this.dgvFind.Location = new System.Drawing.Point(0, 91);
                    this.dgvFind.Size = new Size(731, 230);
                }
                else if (HolderVariables.strFindType == "Port")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(445, 600);
                    this.MaximumSize = new Size(445, 600);
                    this.dgvFind.Location = new System.Drawing.Point(0, 61);
                    this.dgvFind.Size = new Size(431, 141);
                }
                else if (HolderVariables.strFindType == "Post")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(445, 521);
                    this.MaximumSize = new Size(445, 521);
                    this.dgvFind.Location = new System.Drawing.Point(0, 61);
                    this.dgvFind.Size = new Size(437, 335);
                }
                else if (HolderVariables.strFindType == "GeneralMeasurement")
                {
                    //445, 521
                    set_GRNSearchHide();
                    this.Size = new Size(445, 521);
                    this.MaximumSize = new Size(445, 521);
                    this.dgvFind.Location = new System.Drawing.Point(0, 61);
                    this.dgvFind.Size = new Size(437, 368);
                }
                else if (HolderVariables.strFindType == "ShipperMeasurement")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(445, 521);
                    this.MaximumSize = new Size(445, 521);
                    this.dgvFind.Location = new System.Drawing.Point(0, 61);
                    this.dgvFind.Size = new Size(437, 368);
                }
                else if (HolderVariables.strFindType == "KOP")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(445, 521);
                    this.MaximumSize = new Size(445, 521);
                    this.dgvFind.Location = new System.Drawing.Point(0, 61);
                    this.dgvFind.Size = new Size(437, 368);
                }
                else if (HolderVariables.strFindType == "Area")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(445, 296);
                    this.MaximumSize = new Size(445, 296);
                    this.dgvFind.Location = new System.Drawing.Point(0, 61);
                    this.dgvFind.Size = new Size(431, 141);
                }
                else if (HolderVariables.strFindType == "PortArea")
                {
                    set_GRNSearchHide();
                    this.Size = new Size(445, 296);
                    this.MaximumSize = new Size(445, 296);
                    this.dgvFind.Location = new System.Drawing.Point(0, 61);
                    this.dgvFind.Size = new Size(431, 141);
                }
                //
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_FormDesign"); 
            }
        }

        public frmFindCompany(string strFindType)
        {
            try
            {
                InitializeComponent();
                set_FormDesign(strFindType);    
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " frmFindCompany"); 
            }
        }

        public frmFindCompany()
        {
            // TODO: Complete member initialization
        }

        private void frmFindCompany_Load(object sender, EventArgs e)
        {
            try
            {
                ((GridTableElement)this.dgvFind.TableElement).RowHeight = 20;
                timer1.Start();
                _BUS = new clsBUS();
                TimerDelay = new clsTimerDelay();

                _BUS.getset_FindType = HolderVariables.strFindType;
                _BUS.set_DALConnection();
                setFindType(HolderVariables.strFindType);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " frmFindCompany_Load"); 
            }
        }

        //get the field name from the gridview to be used in search.
        //every column name in the gridview is the exact name in db table field.
        private string get_FieldName()
        {
            string strFieldName = string.Empty;
            try
            {
                if (dgvFind.Columns.Count > 0 && ddlFindBy.Text.Trim () != string.Empty)
                {
                    for (int intCol = 0; intCol < dgvFind.Columns.Count; intCol++)
                    {
                        if (ddlFindBy.Text.Trim() == dgvFind.Columns[intCol].HeaderText.Trim())
                        {
                            strFieldName = dgvFind.Columns[intCol].Name.Trim();
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_FieldName"); 
            }

            return strFieldName;
        }

        private void set_CheckGridColumns()
        {
            if (dgvFind.Columns.Count > 0)
            {
                dgvFind.Columns.Clear();
            }
        }
     
        protected void setFindType(string strType)
        {
            try
            {
                if (HolderVariables.strFindType.Trim() == "Company")
                {
                    set_findCompanyColumns();
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);
                }
                else if (HolderVariables.strFindType.Trim() == "AddressDetails")
                {
                    set_findAddressDetailsColumns();
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);
                    set_CriteriaAddress();
                }
                else if (HolderVariables.strFindType.Trim() == "Zone")
                {
                    set_ZoneColumns();
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);
                   // set_CriteriaAddress();
                }
                else if (HolderVariables.strFindType.Trim() == "GRN")
                {
                    set_GridColumnsGRN();
                    setSeachCriteriaDDl();
                    _BUS.getset_FindType = strType;
                    _BUS.getset_GRNFeildSearch = get_FieldName();
                    _BUS.getset_GRNSearchValue = txtSearch.Text.Trim();
               
                    _BUS.getset_GRNTop = Convert.ToInt32(mskTop.Value);
                    _BUS.set_FindQuery(strType);
                }
                else if (HolderVariables.strFindType.Trim() == "Port")
                {
                    set_GridColumnsPort();
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);

                }
                else if (HolderVariables.strFindType.Trim() == "Post")
                {
                    set_GridColumnsPost();
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);
                }
                else if (HolderVariables.strFindType.Trim() == "GeneralMeasurement")
                {
                    set_GridcolumnsGeneralMeasurement();
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);
                    set_LoadAllGeneralAndShipperMeasurement();
                }
                else if (HolderVariables.strFindType.Trim() == "ShipperMeasurement")
                {
                    set_GridColumnShipperMeasurement(); 
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);
                    set_LoadAllGeneralAndShipperMeasurement();
                }
                else if (HolderVariables.strFindType.Trim() == "KOP")
                {
                    set_GridColumnKOP();
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);
                    set_LoadAllGeneralAndShipperMeasurement();
                }
                else if (HolderVariables.strFindType.Trim() == "Area")
                {
                    set_GridColumnsArea();
                    setSeachCriteriaDDl();
                    _BUS.set_FindQuery(strType);
                }
                else if (HolderVariables.strFindType.Trim() == "PortArea")
                {
                    set_GridPortArea();
                    setSeachCriteriaDDl();
                    _BUS.getset_PortAreaID = getset_PortAreaID;
                    _BUS.set_FindQuery(strType);
                }
               
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " setFindType"); 
            }
        }

      
        private void set_CriteriaAddress()
        {
            if (getset_SearchType == "City")
            {
                ddlFindBy.SelectedValue = "City Code";
            }
            else if (getset_SearchType == "Area")
            {
                ddlFindBy.SelectedValue = "Area Code";
            }
            else if (getset_SearchType == "State")
            {
                ddlFindBy.SelectedValue = "State Name";
            }
            else if (getset_SearchType == "Country")
            {
                ddlFindBy.SelectedValue = "Country Code";
            }
        }

        //add all available seach criteria in the combo box.
        private void setSeachCriteriaDDl()
        {
            try
            {
                if (ddlFindBy.Items.Count > 0)
                {
                    ddlFindBy.Items.Clear();
                }
                for(int intColIndex = 0; intColIndex < dgvFind.Columns.Count; intColIndex++)
                {
                    if (dgvFind.Columns[intColIndex].HeaderText.Trim() != "comidHQ")
                    {
                        ddlFindBy.Items.Add(dgvFind.Columns[intColIndex].HeaderText.Trim()); 
                    }
                }
                ddlFindBy.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " setSeachCriteriaDDl"); 
            }
        }

        private void set_Seach()
        {
            try
            {
                if (ddlFindBy.Text.Trim() != string.Empty)
                {
                    if (txtSearch.Text.Trim() != string.Empty && Convert.ToInt32(mskTop.Value) > 0)
                    {          
                        if (txtSearch.Text.Length < 2)
                        {
                            TimerDelay.RevokeQueryTimer();
                        }
                        else
                        {
                            TimerDelay.RestartQueryTimer();
                        }
                    }
                }
                else
                {
                    dgvFind.Rows.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_Seach"); 
            }
        }

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            try
            {
                set_Seach();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " txtSearch_TextChanged"); 
            }
            
        }
        //remove the commas generated by the maskeeditbox
        private string set_RemoveComma(string strValue)
        {
            string strNoComma = string.Empty;
            try
            {
                string strcheck = string.Empty ;

                for (int intChar = 0; intChar < strValue.Length; intChar++)
                {
                    strcheck = strValue.Trim().Substring(intChar, 1).Trim();
                    if (strcheck != ",")
                    {
                        strNoComma += strcheck;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_RemoveComma"); 
            }
            return strNoComma;
        }

        private void set_BestFitcolumn()
        {
            for (int intCols = 0; intCols < dgvFind.Columns.Count; intCols++)
            {
                dgvFind.Columns[intCols].BestFit();
            }
        }
        
        private void set_LoadToGridGRN()
        {
            try
            {
                _BUS.getset_GRNTop = Convert.ToInt32(mskTop.Value);
                _BUS.getset_GRNFeildSearch = get_FieldName();
                _BUS.getset_GRNSearchValue = txtSearch.Text.Trim();
                _BUS.getset_FindType = "GRN";

                if (chkDateRange.Checked == true)
                {
                    _BUS.getset_GRNDateFromTo = dteFrom.Value.ToString("dd/mm/yyyy") + "_" + dteTo.Value.ToString("dd/mm/yyyy");
                }
                else
                {
                    _BUS.getset_GRNDateFromTo = string.Empty;
                }

                _BUS.set_FindQuery("GRN");

                set_LoadToGridCompany();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadToGridGRN"); 
            }
         }

        private void set_LoadAllGeneralAndShipperMeasurement()
        {
            try
            {
               // set_AddRowsToGrid
                // _BUS.get_Search
                int intRows = 50;
                DataRow[] dr = _BUS.get_Search (string.Empty);

                if (dr.Length > 50)
                {
                    intRows = 30;
                }
                else
                {
                    intRows = dr.Length;
                }

                for (int intRow = 0; intRow < Convert.ToInt32(set_RemoveComma(mskTop.Value.ToString())); intRow++)
                {
                    set_AddRowsToGrid(dr, intRow); 
                }
                dgvFind.BestFitColumns();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadAllGeneralAndShipperMeasurement"); 
            }
        }

        private DataRow[] get_SearchQuery()
        {
            DataRow[] drSearch = { };
            try
            {
                if (HolderVariables.strFindType.Trim() != "GRN")
                {
                    drSearch = _BUS.get_Search(get_FieldName() + " like '*" + txtSearch.Text.Trim() + "*'");
                }
                else if (HolderVariables.strFindType.Trim() == "GRN")
                {
                    drSearch = _BUS.get_SearhAll();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_SearchQuery"); 
            }
            return drSearch;
        }

        private void set_ColumnBestFit()
        {
            dgvFind.ClearSelection();
            dgvFind.Rows[0].IsCurrent = true;
            dgvFind.Columns[0].BestFit();
        }

        private void set_ClearRows()
        {
            if (dgvFind.Rows.Count > 0)
            {
                //clear the rows if there are rows that exists.
                dgvFind.Rows.Clear();
            }
        }

        private void set_AddRowsToGrid(DataRow[] drCompany, int intRow)
        {
            //add the values from db.
            try
            {
               GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(this.dgvFind.MasterView);
                for (int intCol = 0; intCol < dgvFind.Columns.Count; intCol++)
                {
                    rowInfo.Cells[dgvFind.Columns[intCol].Name].Value = clsGenFunction.get_checkStringNull(drCompany[intRow][dgvFind.Columns[intCol].Name]).ToString().Trim();
                }
                dgvFind.Rows.Add(rowInfo);
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_AddRowsToGrid"); 
            }
        }

        private void set_LoadToGridCompany()
        {
            try
            {
                int intRowCount = Convert.ToInt32(set_RemoveComma(mskTop.Value.ToString()));
                DataRow[] drCompany = { };

                set_ClearRows();
                
                if (intRowCount > 0)
                {
                   drCompany = get_SearchQuery();
                    for (int intRow = 0; intRow < intRowCount; intRow++)
                    {
                        if (intRow < drCompany.Length)
                        {
                           set_AddRowsToGrid(drCompany,intRow);
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (dgvFind.Rows.Count > 0 && drCompany.Length > 0)
                    {
                        dgvFind.BestFitColumns();
                    }
                }
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadToGridCompany"); 
            }
        }

        //set the columns for company search
        private void set_findCompanyColumns()
        {
            try
            {
                set_CheckGridColumns();
                dgvFind.Columns.Add("comname", "Name");
                dgvFind.Columns.Add("comname2", "Name 2");
                dgvFind.Columns.Add("comid", "ID");
                dgvFind.Columns.Add("comregno", "Reg. No.");
                dgvFind.Columns.Add("areacode", "Area Code");
                dgvFind.Columns.Add("citycode", "City Code");
                dgvFind.Columns.Add("poscode", "Post Code");
                dgvFind.Columns.Add("acccode", "Type");
                dgvFind.Columns.Add("comidHQ", "comidHQ");
                dgvFind.Columns.Add("portid", "Port ID");
                dgvFind.Columns["comidHQ"].IsVisible = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libCommonTools_frmFindCompany_set_findCompany");
            }
        }

        private void set_findAddressDetailsColumns()
        {
            try
            {

                set_CheckGridColumns();
                dgvFind.Columns.Add("areacode", "Area Code");
                dgvFind.Columns.Add("areaname", "Area Name");
                dgvFind.Columns.Add("citycode", "City Code");
                dgvFind.Columns.Add("cityname", "City Name");
                dgvFind.Columns.Add("statecode", "State Code");
                dgvFind.Columns.Add("statename", "State Name");
                dgvFind.Columns.Add("coucode", "Country Code");
                dgvFind.Columns.Add("coudes", "Country Name");
                dgvFind.Columns.Add("regcode", "Region Code");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libCommonTools_frmFindCompany_set_findCompany");
            }
        }
         // discode, disname, description as ZoneDesc
        private void set_ZoneColumns()
         {
             set_CheckGridColumns();
             dgvFind.Columns.Add("discode", "Zone Code");
             dgvFind.Columns.Add("disname", "Zone Name");
             dgvFind.Columns.Add("ZoneDesc", "Zone Description");
         }

        private void set_GridColumnsPort()
         {
             set_CheckGridColumns();
             dgvFind.Columns.Add("PortID", "Port ID");
             dgvFind.Columns.Add("PortName", "Name");
         }

        private void set_GridColumnsArea()
        {
            set_CheckGridColumns();
            dgvFind.Columns.Add("areacode", "Area ID");
            dgvFind.Columns.Add("areaname", "Area Name");
        }

        private void set_GridPortArea()
        {
            set_CheckGridColumns();
            dgvFind.Columns.Add("PostCode", "Code");
            dgvFind.Columns.Add("AreaDescription", "Area Description");
        }
        
        private void set_GridColumnsPost()
         {
             set_CheckGridColumns();
             dgvFind.Columns.Add("Code", "Code");
             dgvFind.Columns.Add("Name", "Name");
         }
        
        private void set_GridcolumnsGeneralMeasurement()
        {
            set_CheckGridColumns();
            dgvFind.Columns.Add("cargocode", "Code");
            dgvFind.Columns.Add("cargodes", "Description");
            //dgvFind.Columns["cargocode"].Width = "100";
        }

        private void set_GridColumnShipperMeasurement()
        {
            set_CheckGridColumns();
            dgvFind.Columns.Add("indcode", "Code");
            dgvFind.Columns.Add("inddes", "Description");
        }

        private void set_GridColumnKOP()
        {
            //indcode, inddes
            set_CheckGridColumns();
            dgvFind.Columns.Add("indcode", "Code");
            dgvFind.Columns.Add("inddes", "Description");
        }
        
        private void set_GridColumnsGRN()
         {
             try
             {
                 set_CheckGridColumns();
                 dgvFind.Columns.Add("connoteno", "GRN No.");
                 dgvFind.Columns.Add("shipname", "Shipper Name");
                 dgvFind.Columns.Add("comname", "Consignee Name");
                 dgvFind.Columns.Add("connotedate", "GRN Date");
                 dgvFind.Columns.Add("shipinvno", "Invoice No.");
                 dgvFind.Columns.Add("trastacode", "Status");
                 dgvFind.Columns.Add("stickno", "Sticker No.");
                 dgvFind.Columns.Add("shipid", "Shipper ID");
                 dgvFind.Columns.Add("conid", "Consignee ID");
                 dgvFind.Columns.Add("refno", "Ref. No");
                 dgvFind.Columns.Add("portid", "Port ID");
                 dgvFind.Columns.Add("speins", "Shipping Instruction");
                 dgvFind.Columns.Add("totqty", "Total QTY");
                 dgvFind.Columns.Add("totcbm", "Total CBM");
                 dgvFind.Columns.Add("totwei", "Total Weight");
                 dgvFind.Columns.Add("issby", "Issued by");
                 dgvFind.Columns.Add("vehplano", "Vehicle No.");
                 dgvFind.Columns.Add("grntypecode", "Type");
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_GridColumns");
             }
         }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (TimerDelay.get_CheckStoped == true)
            {
                if (HolderVariables.strFindType.Trim() != "GRN")
                {
                    set_LoadToGridCompany();
                    TimerDelay.get_CheckStoped = false;
                }
                else if (HolderVariables.strFindType.Trim() == "GRN")
                {
                    set_LoadToGridGRN();
                    TimerDelay.get_CheckStoped = false;
                }
            }
        }

        private void txtSearch_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                set_CompanyID();
                DialogResult = DialogResult.OK;
            }
        }

        public string get_CompanyIDHQ()
        {
            //comidHQ
            string strIDHQ = string.Empty;
            string strAbc = string.Empty;
            if (dgvFind.CurrentRow.Cells["comidHQ"].Value.ToString().Trim() != string.Empty)
            {
                 strIDHQ = dgvFind.CurrentRow.Cells["comidHQ"].Value.ToString().Trim();
                 strAbc = strIDHQ.Substring(0, strIDHQ.LastIndexOf("_"));
            }
            return strAbc;
        }

        private void set_CompanyID()
        {
            if (dgvFind.SelectedRows.Count > 0)
            {
                this.strcCompanyG.strCompanyID = dgvFind.CurrentRow.Cells["comid"].Value.ToString();
                this.strcCompanyG.strCompanyType = dgvFind.CurrentRow.Cells["acccode"].Value.ToString();
                this.strcCompanyG.strCompanyName = dgvFind.CurrentRow.Cells["comname"].Value.ToString();
                this.strcCompanyG.strCompanyPortID = dgvFind.CurrentRow.Cells["portid"].Value.ToString();
               
            }
        }
       
        public string get_CompanyName
        {
            get
            {
                return this.strcCompanyG.strCompanyName;
            }
        }

        public string get_AreaName
        {
            get
            {
                return strcAddressG.strAreaname;
            }
        }

        public string get_CityCode
        {
            get
            {
              return   strcAddressG.strCitycode;
            }
        }

        public string get_CityName
        {
            get
            {
               return strcAddressG.strCitycodeName;
            }
        }

        public string get_StateCode
        {
            get
            {
               return  strcAddressG.strStatecode;
            }
        }

        public string get_StateName
        {
            get
            {
                return strcAddressG.strStateName;
            }
        }

        public string get_PortID
        {
            get
            {
                return this.strcCompanyG.strCompanyPortID;
            }
        }

        public string get_PortName
        {
            get
            {
                return strcPortDetails.strPortName;
            }
        }

        public string get_CountryCode
        {
            get
            { 
                return  strcAddressG.strCoucode; 
            }
        }

        public string get_CountryName
        {
            get
            {
                return strcAddressG.strCouName;
            }
        }

        public string get_AreaCode
        {
            get
            {
                return strcAddressG.strAreacode;
            }
        }

        public string get_ZoneCode
        {
            get
            {
                return strcAddressG.strZoneCode;
            }
        }

        public string get_ZoneName
        {
            get
            {
                return strcAddressG.strZoneName;
            }
        }

        public string get_PostCode
        {
            get
            {
                return strcPostDetails.strPostID; 
            }
        }

        public string get_PostName
        {
            get
            {
                return strcPostDetails.strPostName;  
            }
        }

        public string get_GenMeasurmentID
        {
            get
            {
                return strGenMeasurement.strCode;
            }
        }

        public string get_GenMeasurmentName
        {
            get
            {
                return strGenMeasurement.strDescription; 
            }
        }

        public string get_ShipperMeasurmentID
        {
            get
            {
                return strShippMeasurement.strCode;  
            }
        }

        public string get_ShipperMeasurmentName
        {
            get
            {
                return strShippMeasurement.strDescription;
            }
        }

        private void set_ZoneDetails()
        {
            try
            {
                if (dgvFind.SelectedRows.Count > 0)
                {
                    strcAddressG = new AddressDetails();
                    strcAddressG.strZoneCode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["discode"].Value);
                    strcAddressG.strZoneName = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["disname"].Value);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ZoneDetails"); 
            }
        }

        private void set_PostDetails()
        {
            try
            {
                strcPostDetails = new PostDetails();
                strcPostDetails.strPostID = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["Code"].Value);
                strcPostDetails.strPostName = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["Name"].Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_PostDetails"); 
            }
        }

        private void set_GeneralMeasurement()
        {
            try
            {
                strGenMeasurement = new GeneralMeasurement();
                strGenMeasurement.strCode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["cargocode"].Value);
                strGenMeasurement.strDescription = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["cargodes"].Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_PostDetails");
            }
        }

        public string get_Description
        {
            get
            {
                return strcCodeDescription.strDescription; 
            }
        }

        public string get_Code
        {
            get
            {
                return strcCodeDescription.strCode; 
            }
        }

        private void set_Area()
        {
            try
            {
                strcCodeDescription = new CodeDescription();
                strcCodeDescription.strCode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["areacode"].Value);
                strcCodeDescription.strDescription = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["areaname"].Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_PostDetails");
            }
        }

        private void set_KOP()
        {
            try
            {
                //dgvFind.Columns.Add("indcode", "Code");
                //dgvFind.Columns.Add("inddes", "Description");

                strcCodeDescription = new CodeDescription();
                strcCodeDescription.strCode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["indcode"].Value);
                strcCodeDescription.strDescription = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["inddes"].Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_PostDetails");
            }
        }

        private void set_PortArea()
        {
            try
            {
                string strPortID = string.Empty;
                string strAreaID = string.Empty;

                strPortID = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["PostCode"].Value);
                strPortID = getset_PortAreaID;

             //   _BUS.getset_PortArea();
               
              //dgvFind.Columns.Add("PostCode", "Code");
              //dgvFind.Columns.Add("AreaDescription", "Area Description");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_PortArea"); 
            }
        }
        

        private void set_ShipperMeasurement()
        { 
           // indcode, inddes
            strShippMeasurement = new ShipperMeasurement();
            strShippMeasurement.strCode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["indcode"].Value);
            strShippMeasurement.strDescription = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["inddes"].Value);
           
        }

        private void set_PortDetails()
        {
            try
            {
                if (dgvFind.SelectedRows.Count > 0)
                {
                    strcPortDetails.strPortID = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["PortID"].Value);
                    strcPortDetails.strPortName = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["PortName"].Value);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_PortDetails"); 
            }
        }

        private void set_AddressDetails()
        {
            string strStrValue = string.Empty;
            try
            {
                if (dgvFind.SelectedRows.Count > 0)
                {
                    strcAddressG = new AddressDetails();
                    strcAddressG.strAreacode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["areacode"].Value);
                    strcAddressG.strAreaname = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["areaname"].Value);
                    strcAddressG.strCitycode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["citycode"].Value);
                    strcAddressG.strCitycodeName = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["cityname"].Value);
                    strcAddressG.strStatecode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["statecode"].Value);
                    strcAddressG.strStateName = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["statename"].Value);
                    strcAddressG.strCoucode = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["coucode"].Value);
                    strcAddressG.strCouName = clsGenFunction.get_checkStringNull(dgvFind.CurrentRow.Cells["coudes"].Value);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_AddressDetails"); 
            }
        }


        private bool set_Setters()
        {
            bool bolStatus = false;
            try
            {
                if (HolderVariables.strFindType.Trim() == "Company")
                {
                    set_CompanyID();
                }
                else if (HolderVariables.strFindType.Trim() == "AddressDetails")
                {
                    set_AddressDetails();
                }
                else if (HolderVariables.strFindType.Trim() == "Zone")
                {
                    set_ZoneDetails();
                }
                else if (HolderVariables.strFindType.Trim() == "GRN")
                {
                    getset_GRNNumber = dgvFind.CurrentRow.Cells["connoteno"].Value.ToString();
                }
                else if (HolderVariables.strFindType.Trim() == "Port")
                {
                    set_PortDetails();
                }
                else if (HolderVariables.strFindType.Trim() == "Post")
                {
                    set_PostDetails();
                }
                else if (HolderVariables.strFindType.Trim() == "GeneralMeasurement")
                {
                    set_GeneralMeasurement();
                }
                else if (HolderVariables.strFindType.Trim() == "ShipperMeasurement")
                {
                    set_ShipperMeasurement();
                }
                else if (HolderVariables.strFindType.Trim() == "Area")
                {
                    set_Area();
                }
                else if (HolderVariables.strFindType.Trim() == "KOP")
                {
                    set_KOP();
                }

                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_Setters"); 
            }

            return bolStatus; 
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvFind.SelectedRows.Count > 0)
                {
                    if (set_Setters() == true)
                    {
                        DialogResult = DialogResult.OK;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " btnOK_Click");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.strcCompanyG. strCompanyID = string.Empty;
            DialogResult = DialogResult.Cancel;
        }

        private void txtSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (txtSearch.Text.Trim() == string.Empty)
            {
                dgvFind.Rows.Clear();
            }  
        }

        private void mskTop_TextChanged(object sender, EventArgs e)
        {
            set_Seach();
        }

        private void ddlFindBy_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            set_Seach();
        }

        private void dgvFind_CellDoubleClick(object sender, GridViewCellEventArgs e)
        {
            try
            {
                if (set_Setters() == true)
                {
                    DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " dgvFind_CellDoubleClick"); 
            }
        }

        private void dgvFind_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (char)Keys.Return)
            {
                if (HolderVariables.strFindType.Trim() == "Company")
                {
                    set_CompanyID();
                }
                else if (HolderVariables.strFindType.Trim() == "AddressDetails")
                {
                    set_AddressDetails();
                }
                DialogResult = DialogResult.OK;
            }
        }

        private void frmFindCompany_KeyUp(object sender, KeyEventArgs e)
        {
            
        }

        private void frmFindCompany_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                DialogResult = DialogResult.Cancel;
            }
        }

        private void chkDateRange_CheckedChanged(object sender, EventArgs e)
        {
            if (chkDateRange.Checked == true)
            {
                dteFrom.Enabled = true;
                dteTo.Enabled = true;
            }
            else
            {
                dteFrom.Enabled = false;
                dteTo.Enabled = false;
            }
        }


        public string getset_PortAreaID { get; set; }
    }
}
